import { getToken, setToken, removeToken } from '@/utils/auth'
import { login } from '@/api/user'
// import { login, getInfo } from '@/api/user'

const state = {
  token: getToken(),
  userInfo: {}
}
const mutations = {
  SET_TOKEN(state, token) {
    state.token = token
    setToken(token)
  },
  REMOVE_TOKEN(state) {
    state.token = ''
    removeToken()
  }
  // SET_USER_INFO(state, data) {
  //   state.userInfo = { ...data }
  // },
  // REMOVE_USER_INFO(state) {
  //   state.userInfo = {}
  // }

}
const actions = {
  async login(context, data) {
    const res = await login(data)
    console.log(res)
    if (res) {
      context.commit('SET_TOKEN', res.data.data.token)
    }
  },
  // async getUserInfo(context) {
  //   const res = await getInfo()
  //   context.commit('SET_USER_INFO', res.data)
  // },
  logout(context) {
    context.commit('REMOVE_TOKEN')
    // context.commit('REMOVE_USER_INFO')
  }

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

